.TH std::vector::assign_range 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::vector::assign_range \- std::vector::assign_range

.SH Synopsis
   template< container-compatible-range<T> R >  (since C++23)
   constexpr void assign_range( R&& rg );

   Replaces elements in the container with a copy of each element in rg.

   All iterators (including the end() iterator) and references to the elements are
   invalidated.

   Each iterator in the range rg is dereferenced exactly once.

   The behavior is undefined if rg overlaps with the container.

.SH Parameters

   rg                -               an input_range with reference type convertible to
                                     the element type of the container
.SH Type requirements
   -
   std::assignable_from<T&, ranges::range_reference_t<R>> must be modeled. Otherwise,
   the program is ill-formed.
   -
   T must be EmplaceConstructible into the container from *ranges::begin(rg). If R
   models neither sized_range nor forward_range, T must be also MoveInsertable into the
   container. Otherwise, the behavior is undefined.

.SH Return value

   \fI(none)\fP

.SH Notes

       Feature-test macro       Value    Std                   Feature
   __cpp_lib_containers_ranges 202202L (C++23) Ranges-aware construction and insertion

.SH Example


// Run this code

 #include <algorithm>
 #include <cassert>
 #include <vector>
 #include <list>

 int main()
 {
     const auto source = std::list{2, 7, 1};
     auto destination = std::vector{3, 1, 4};
 #ifdef __cpp_lib_containers_ranges
     destination.assign_range(source);
 #else
     destination.assign(source.cbegin(), source.cend());
 #endif
     assert(std::ranges::equal(source, destination));
 }

.SH See also

   insert_range inserts a range of elements
   (C++23)      \fI(public member function)\fP
   append_range adds a range of elements to the end
   (C++23)      \fI(public member function)\fP
   assign       assigns values to the container
                \fI(public member function)\fP
